﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace WeiXinPF.Modules.Core.Admin.Application.Services
{
    /// <summary>
    /// 
    /// </summary>
    public class AdvertisementParser
    {
        /// <summary>
        /// 将DataRow转化为advertisement对象
        /// </summary>
        /// <param name="dataRow"></param>
        /// <returns></returns>
        public Model.advertisement ParseAdvertisement(DataRow dataRow)
        {
            Model.advertisement ad = new Model.advertisement();
            ad.id = Convert.ToInt32(dataRow["id"].ToString());
            return ad;
        }

        /// <summary>
        /// 将DataRow集合转化为advertisement对象集合
        /// </summary>
        /// <param name="dataRows"></param>
        /// <returns></returns>
        public List<Model.advertisement> ParseAdvertisements(DataRow[] dataRows)
        {
            if (dataRows == null || dataRows.Length == 0)
            {
                return new List<Model.advertisement>();
            }

            List<Model.advertisement> ads = new List<Model.advertisement>();

            dataRows.ToList().ForEach(p => {
                ads.Add(this.ParseAdvertisement(p));
            });
            return ads;
        }
    }
}
